validate-forms.js 559 B

12345678910111213141516171819
  1. // Example starter JavaScript for disabling form submissions if there are invalid fields
  2. (() => {
  3. 'use strict'
  4. // Fetch all the forms we want to apply custom Bootstrap validation styles to
  5. const forms = document.querySelectorAll('.needs-validation')
  6. // Loop over them and prevent submission
  7. Array.from(forms).forEach(form => {
  8. form.addEventListener('submit', event => {
  9. if (!form.checkValidity()) {
  10. event.preventDefault()
  11. event.stopPropagation()
  12. }
  13. form.classList.add('was-validated')
  14. }, false)
  15. })
  16. })()